package com.liuyi.framework.init;

import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextRefreshedEvent;

import java.util.Map;

/**
 * @author Mr.fmy
 * @version 1.0.0
 * @ClassName SpringInitConfig
 * @Description TODO Spring 初始化配置类
 * @createTime 2020/4/25 17:07
 */
public class SpringInitConfig implements ApplicationListener<ContextRefreshedEvent> {

    @Override
    public void onApplicationEvent(ContextRefreshedEvent contextRefreshedEvent) {
        ApplicationContext context = contextRefreshedEvent.getApplicationContext();
        Map<String, SpringInit> inits = context.getBeansOfType(SpringInit.class);
        inits.forEach((k, v) -> v.init(context));
    }

    public interface SpringInit {

        /**
         * 初始化
         */
        void init(ApplicationContext context);
    }
}
